<template>
  <BaseForm
    labelWidth="100px"
    :fromIems="fromIems"
    :size="'medium'"
    ref="BaseForm"
    @submit="submit"
    @edit="edit"
  >
    <template #topbtn>
      <el-button icon="el-icon-setting" type="primary" @click="confrim"
        >发送工厂设置命令</el-button
      >
    </template>
  </BaseForm>
</template>

<script>
import { Message } from "element-ui";
import { getDeviceInfo, sendgccmd, sendjxcmd } from "@/api/device";
export default {
  data() {
    return {
      title: "",
      fromIems: [
        {
          valueType: "select",
          label: "风机检测",
          dataIndex: "fanDetection",
          options: [
            {
              label: "关闭",
              value: 0,
            },
            {
              label: "打开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "开机图片",
          dataIndex: "powerOnImage",
          options: [
            {
              label: "中性",
              value: 0,
            },
            {
              label: "定义",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "按键类",
          dataIndex: "keyType",
          options: [
            {
              label: "四建",
              value: 0,
            },
            {
              label: "梭轮",
              value: 1,
            },
          ],
        },
        {
          valueType: "input",
          label: "Y轴角度",
          dataIndex: "yAxisAngle",
          props:{
            placeholder:'请输入(0-255)',
            style:{
              width:'220px'
            }
          }
        },
        {
          valueType: "input",
          label: "X主动轮",
          dataIndex: "xDriveWheel",
          props:{
            placeholder:'请输入(0-255)',
            style:{
              width:'220px'
            }
          }
        },
        {
          valueType: "input",
          label: "X从动轮",
          dataIndex: "xFollowerWheel",
          props:{
            placeholder:'请输入(0-255)',
            style:{
              width:'220px'
            }
          }
        },
        {
          valueType: "input",
          label: "Y主动轮",
          dataIndex: "yDriveWheel",
          props:{
            placeholder:'请输入(0-255)',
            style:{
              width:'220px'
            }
          }
        },
        {
          valueType: "input",
          label: "Y从动轮",
          dataIndex: "yFollowerWheel",
          props:{
            placeholder:'请输入(0-255)',
            style:{
              width:'220px'
            }
          }
        },
        {
          valueType: "select",
          label: "颜色校正",
          dataIndex: "colorCalibration",
          options: [
            {
              label: "关闭",
              value: 0,
            },
            {
              label: "打开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "角度检测",
          dataIndex: "angleDetection",
          options: [
            {
              label: "关闭",
              value: 0,
            },
            {
              label: "打开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "灯具型号",
          dataIndex: "lightingModel",
          options: [
            {
              label: "默认",
              value: 0,
            },
            {
              label: "工程",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "触摸开关",
          dataIndex: "touchSwitch",
          options: [
            {
              label: "关闭",
              value: 0,
            },
            {
              label: "打开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "锁灯状态",
          dataIndex: "lockSetting",
          options: [
            {
              label: "解锁",
              value: 0,
            },
            {
              label: "上锁",
              value: 1,
            },
          ],
        },
      ],
      isEdit: false,
    };
  },
  methods: {
    open(res,data) {
      const info = res.content;
      console.log(data,'工厂----')
      if (data.facSettings && JSON.parse(data.facSettings)) {
        for (var k in JSON.parse(data.facSettings)) {
          this.$set(
            this.$refs.BaseForm.form,
            k,
            JSON.parse(data.facSettings)[k]
          );
        }
      }
      this.$nextTick(() => {
        console.log(res.content["imei"])
        this.$set(this.$refs.BaseForm.form, "imei", res.content["imei"]);
      });
    },
    close() {
      this.$refs.baseDialog.close();
      this.$refs.BaseForm.rest();
    },
    confrim() {
      if (this.isEdit) {
        this.$refs.BaseForm.edit();
      } else {
        this.$refs.BaseForm.submit();
      }
    },
    async submit(data) {
      const res = await sendgccmd(data);
      if (!res.status) {
        Message.success("发送工厂设置命令成功");
      }
    },
    async edit(data) {
      const res = await sendgccmd({
        imei: data.imei,
        fanDetection: data.fanDetection,
        powerOnImage: data.powerOnImage,
        keyType: data.keyType,
        yAxisAngle: data.yAxisAngle,
        xDriveWheel: data.xDriveWheel,
        xFollowerWheel: data.xFollowerWheel,
        yDriveWheel: data.yDriveWheel,
        yFollowerWheel: data.yFollowerWheel,
        colorCalibration: data.colorCalibration,
        angleDetection: data.angleDetection,
        lightingModel: data.lightingModel,
        touchSwitch: data.touchSwitch,
        lockSetting: data.lockSetting,
      });
      if (!res.status) {
        Message.success("发送工厂设置命令成功");
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
